﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace RoboRun
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class TouchDevelopConversion : Page
    {
        float height;
        float width;
        float offset;
        public TouchDevelopConversion()
        {
            this.InitializeComponent();
            height = MainMenu.height;
            width = MainMenu.width;
            offset = MainMenu.offset;
            codeOutput.Margin = new Thickness(0, offset, 0, 0);
            codeOutputScrollViewer.Margin = new Thickness(0, offset, 0, 0);
            codeOutputScrollViewer.Height = height - 2 * offset;
            conversionInstructions.Margin = new Thickness(3*width/4, offset + height/7, 0, 0);
            conversionInstructions.TextAlignment = TextAlignment.Center;
            title.Margin = new Thickness(3 * width / 4, offset, 0, 0);
            title.Height = height / 7;
            title.TextAlignment = TextAlignment.Center;
            title.FontSize = height / 20;
            title.Width = width / 4;
            title.TextWrapping = TextWrapping.Wrap;
           
            returnToMenu.Width = 215 * width / 1920;
            returnToMenu.Height = 100 * height / 1080;
            returnToMenu.Margin = new Thickness(3.3 * width / 4, 5.7*height/7, 0, 0);
            returnToMenu.FontSize = height / 60;
            returnToMenu.HorizontalContentAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            resizeTextBox();
            resizeInstructions();
            resizeFont();
            conversionInstructions.Text = "Your solution has been converted to TouchDevelop compatible code.\n\nYou can copy and paste this code into the RoboRun TouchDevelop library and do even more with your generated code!";
            codeOutput.Text = TouchDevelopCode.outputCode();
            codeOutput.TextAlignment = TextAlignment.Left;
            codeOutput.IsTextSelectionEnabled = true;
        }

        private void resizeInstructions()
        {
            conversionInstructions.Width = width / 4;
            conversionInstructions.Height = height - 2 * offset;
        }

        private void resizeFont()
        {
            codeOutput.FontSize = height / 15;
            conversionInstructions.FontSize = height / 25;
        }

        private void resizeTextBox()
        {
            codeOutput.Width = 3 * width/4 - 50*width/1920;
            codeOutput.Height = height - 2*offset;
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void returnToMenu_Click_1(object sender, RoutedEventArgs e)
        {
            TouchDevelopCode.TDQueue.Clear();
            this.Frame.Navigate(typeof(MainMenu)); //change to level select screen
            
        }
    }
}
